@tool
class_name CompositeProperty
extends Resource

enum PropertyType
{
	String,
	Int,
	Float,
	Bool,
	EntityData,
	Camp,
	RenderLayerMask,
	PhysicsLayerMask,
	Vector2,
	EntityDataString,
}

@export var property_type:PropertyType:
	set(value):
		property_type = value
		notify_property_list_changed()
@export var property_string:String
@export var property_int:int
@export var property_float:float
@export var property_bool:bool
@export var property_entity_data_attribute:String
@export var property_entity_data_default:float
@export var property_camp:GameEnum.Camp
@export_flags_2d_render var property_render_layer_mask:int
@export_flags_2d_physics var property_physics_layer_mask:int
@export var property_vector2:Vector2
@export var property_entity_data_string_default:String

signal property_changed(composite_property:CompositeProperty)

func init(property_type:PropertyType,init_value):
	self.property_type = property_type
	set_value(init_value)
func get_value(entity:Entity = null,args:Dictionary = {}):
	match property_type:
		PropertyType.String:
			return property_string
		PropertyType.Int:
			return property_int
		PropertyType.Float:
			return property_float
		PropertyType.Bool:
			return property_bool
		PropertyType.EntityData:
			if property_entity_data_attribute != "" and entity != null and entity.entity_data != null:
				var data = entity.entity_data.get_attribute_value(property_entity_data_attribute,property_entity_data_default)
				return data
			return property_entity_data_default
		PropertyType.Camp:
			return property_camp
		PropertyType.RenderLayerMask:
			return property_render_layer_mask
		PropertyType.PhysicsLayerMask:
			return property_physics_layer_mask
		PropertyType.Vector2:
			return property_vector2
		PropertyType.EntityDataString:
			if property_entity_data_attribute != "" and entity != null and entity.entity_data != null:
				var data = entity.entity_data.get_attribute_value(property_entity_data_attribute,property_entity_data_string_default)
				return data
			return property_entity_data_string_default
func set_value(value,entity:Entity = null,args:Dictionary = {}):
	match property_type:
		PropertyType.String:
			property_string = value
			property_changed.emit(self)
		PropertyType.Int:
			property_int = value
			property_changed.emit(self)
		PropertyType.Float:
			property_float = value
			property_changed.emit(self)
		PropertyType.Bool:
			property_bool = value
			property_changed.emit(self)
		PropertyType.EntityData:
			pass
		PropertyType.Camp:
			property_camp = value
			property_changed.emit(self)
		PropertyType.RenderLayerMask:
			property_render_layer_mask = value
			property_changed.emit(self)
		PropertyType.PhysicsLayerMask:
			property_physics_layer_mask = value
			property_changed.emit(self)
		PropertyType.Vector2:
			property_vector2 = value
			property_changed.emit(self)
		PropertyType.EntityDataString:
			pass

func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
func _validate_property(property: Dictionary) -> void:
	var hide_list = ["property_string","property_int","property_float","property_bool",
	"property_entity_data_attribute","property_entity_data_default","property_camp",
	"property_render_layer_mask","property_physics_layer_mask","property_vector2",
	"property_entity_data_string_default"]
	match property_type:
		PropertyType.String:
			hide_list.erase("property_string")
		PropertyType.Int:
			hide_list.erase("property_int")
		PropertyType.Float:
			hide_list.erase("property_float")
		PropertyType.Bool:
			hide_list.erase("property_bool")
		PropertyType.EntityData:
			hide_list.erase("property_entity_data_attribute")
			hide_list.erase("property_entity_data_default")
		PropertyType.Camp:
			hide_list.erase("property_camp")
		PropertyType.RenderLayerMask:
			hide_list.erase("property_render_layer_mask")
		PropertyType.PhysicsLayerMask:
			hide_list.erase("property_physics_layer_mask")
		PropertyType.Vector2:
			hide_list.erase("property_vector2")
		PropertyType.EntityDataString:
			hide_list.erase("property_entity_data_attribute")
			hide_list.erase("property_entity_data_string_default")
	if property.name in hide_list:
		property.usage = PROPERTY_USAGE_NO_EDITOR
